import { GameDataModel } from "../GameDataModel";
import { GameEvent } from "../GameEvent";
import { BaseView } from "../ui_view/base/BaseView";

const scoreLabelContent: string = 'Score:';
export class GameView extends BaseView{
    private scoreLabel: cc.Label;

    public constructor(node: cc.Node){
        super(node);
        this.scoreLabel = cc.find('game/game_view/score_label').getComponent(cc.Label);
    }

    public show(): void {
        super.show();
        this.refreshScore();
        GameEvent.OnPlayerGetScore = this.onGetScore.bind(this);
    }

    public hide(): void {
        super.hide();
        GameEvent.OnPlayerGetScore = null;
    }

    private onGetScore(getScore: number): void{
        GameDataModel.getInstance().addScore(getScore);
        this.refreshScore();
    }

    private refreshScore(): void{
        this.scoreLabel.string = scoreLabelContent + GameDataModel.getInstance().getScore().toString();
    }
}